/*
 * Created by SharpDevelop.
 * User: phtrung
 * Date: 5/4/2010
 * Time: 5:14 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Windows.Forms;
using System.Drawing;

namespace popLib.CustomeControl
{
	/// <summary>
	/// Description of FlowAnchorPanel.
	/// </summary>
	public class FlowAnchorPanel:FlowLayoutPanel
	{
		Size currentSize;
		public bool isPainted = false;
		public FlowAnchorPanel()
		{			
			currentSize = this.Size;			
			ClientSizeChanged += delegate(object sender, EventArgs e) {
				if( isPainted )
				foreach( Control control in Controls ){
					if( control.Anchor == (AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom ) ||
					   	control.Anchor == (AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top ) ||
					  	control.Anchor == (AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom ) ||
					  	control.Anchor == (AnchorStyles.Left | AnchorStyles.Right) 
					  ){
						control.Size = new Size( control.Width + (this.Size.Width - currentSize.Width),
						                        control.Height );
					}
				}
				
				//if( isPainted )
				currentSize = this.Size;
			};
			
			HandleCreated += delegate(object sender, EventArgs e) { 
				isPainted = true;
			};
						
			Paint += delegate(object sender, PaintEventArgs e) { 
				isPainted = true;
			};
		}
	}
}
